package com.ask.common.result;

import com.ask.common.enumeration.ResultCode;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Builder
@Data
public class Result {
    private Integer code;
    private String msg;
    private Object data;

    public static Result success() {
        return success(null);
    }

    public static Result success(Object data) {
        return Result.builder()
                .code(ResultCode.SUCCESS.getCode())
                .msg(ResultCode.SUCCESS.getMsg())
                .data(data)
                .build();
    }

    public static Result fail(String msg) {
        return Result.builder()
                .code(ResultCode.FAIL.getCode())
                .msg(msg)
                .build();
    }

    public static Result error(String msg) {
        return Result.builder()
                .code(ResultCode.ERROR.getCode())
                .msg(msg)
                .build();
    }
    public static Result error(Integer code, String msg) {
        return Result.builder()
                .code(code)
                .msg(msg)
                .build();
    }
}
